<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="合作商">
              <j-input
                placeholder="请输入合作商"
                v-model="partnerName"
                type="lk"
                trim
                @change="changePartName"
              ></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="合同状态">
              <j-dict-select-tag placeholder="请选择合同状态" v-model="queryParam.spStatus" dictCode="sp_status" />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="协议类型">
              <a-select v-model="contractType" placeholder="请选择协议类型" @change="changeContarct">
                <a-select-option value="附加协议">附加协议</a-select-option>
                <a-select-option value="框架协议">框架协议</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="10" :lg="11" :md="12" :sm="24">
              <!--
              <a-form-item label="创建日期">
                <j-date placeholder="请选择开始日期" class="query-group-cust" v-model="queryParam.createTime_begin"></j-date>
                <span class="query-group-split-cust"></span>
                <j-date placeholder="请选择结束日期" class="query-group-cust" v-model="queryParam.createTime_end"></j-date>
              </a-form-item>
              -->
              <a-form-item label="生成时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
                <a-range-picker
                  style="width: 210px"
                  v-model="queryParam.createTimeRange"
                  format="YYYY-MM-DD"
                  :placeholder="['开始时间', '结束时间']"
                  @change="onDateChange"
                  @ok="onDateOk"
                />
              </a-form-item>
            </a-col>
          </template>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!--      <a-button type="primary" icon="download" @click="handleExportXls('合同表')">导出</a-button>-->

      <!--
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      -->
      <!-- 高级查询区域
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      -->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <!--        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>-->
        <a-button type="primary" icon="download" @click="downLoadPdf(downContractPdf, 2, '', strSelectedRowKeys)"
          >批量导出</a-button
        >
      </a-dropdown>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <!--        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>-->
        <a-button type="primary" icon="plus" @click="requestServer(null)">批量企业微信提审</a-button>
      </a-dropdown>
      <!--      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-button type="primary" icon="plus" @click="requestServer('createFlyBookExamineBatch')"  >批量飞书提审</a-button>
      </a-dropdown>-->
      <!--      <a-dropdown v-if="selectedRowKeys.length > 0">-->
      <!--        <a-button type="primary" icon="plus" @click="requestServer('createDingTalkExamineBatch')"  >批量钉钉提审</a-button>-->
      <!--      </a-dropdown>-->
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
        >项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <span slot="spRecord" slot-scope="text">
          <j-ellipsis :value="text" :length="20" />
        </span>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt=""
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <!--          <a @click="downLoadPdf(downContractPdf,1,'',record.id)" >下载合同</a>-->
          <!--          <a-button @click="downLoadPdf(downContractPdf,1,'',record.id)">下载合同</a-button>-->
          <!--         <a-divider type="vertical"/>-->
          <!--          <a-dropdown>-->
          <!--            <a-button @click="requestServerOne(record)">提交审批</a-button>-->
          <!--          </a-dropdown>-->
          <a v-if="record.spStatus" @click="downLoadPdf(downContractPdf, 1, '', record.id)">下载</a>
          <a v-else @click="requestServerOne(record)">提审</a>
          <!-- <a-divider type="vertical" /> -->
        </span>
      </a-table>
    </div>

    <hl-contract-modal ref="modalForm" @ok="modalFormOk"></hl-contract-modal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import HlContractModal from './modules/HlContractModal'
export default {
  name: 'HlContractList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    HlContractModal,
  },
  data() {
    return {
      // 之前直接绑定的queryParam对象，由于minxin给queryParam.contractType赋值后选择器无响应
      contractType: '',
      partnerName: '',
      description: '合同表管理页面',
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '生成时间',
          align: 'center',
          dataIndex: 'createTime',
        },
        {
          title: '合作商',
          align: 'left',
          dataIndex: 'partnerName',
        },
        {
          title: '生成合同文本',
          align: 'left',
          dataIndex: 'contractName',
        },
        {
          title: '标准价格协议',
          align: 'left',
          dataIndex: 'settleTemplateName',
        },
        /*{
            title:'合同开始日期',
            align:"center",
            dataIndex: 'contractBegin',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'合同结束日期',
            align:"center",
            dataIndex: 'contractEnd',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'结算开始日期',
            align:"center",
            dataIndex: 'settleBegin',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'结算结束日期',
            align:"center",
            dataIndex: 'settleEnd',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'源Excel',
            align:"center",
            dataIndex: 'pkName',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },*/
        {
          title: '开始日期',
          align: 'center',
          dataIndex: 'contractBegin',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
        {
          title: '结束日期',
          align: 'center',
          dataIndex: 'contractEnd',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
        {
          title: '合同状态',
          align: 'center',
          dataIndex: 'spStatus_dictText',
        },
        {
          title: '协议类型',
          align: 'center',
          dataIndex: 'contractType',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
        {
          title: '提交人',
          align: 'center',
          dataIndex: 'createBy_dictText',
        },
        {
          title: '审批编号',
          align: 'center',
          dataIndex: 'spNo',
        },
        {
          title: '审批节点',
          align: 'left',
          dataIndex: 'spRecord',
          scopedSlots: { customRender: 'spRecord' },
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 70,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/contract/hlContract/list',
        delete: '/contract/hlContract/delete',
        deleteBatch: '/contract/hlContract/deleteBatch',
        exportXlsUrl: '/contract/hlContract/exportXls',
        downContractPdf: 'contract/hlContractTemplate/downContractPdf',
        createExamineBatch: '/contract/hlContract/createExamineBatch',
        createFlyBookExamineBatch: '/contract/hlContract/createFlyBookExamineBatch',
        createDingTalkExamineBatch: '/contract/hlContract/createDingTalkExamineBatch',
        importExcelUrl: 'contract/hlContract/importExcel',
      },
      labelCol: {
        xs: { span: 1 },
        sm: { span: 2 },
      },
      wrapperCol: {
        xs: { span: 10 },
        sm: { span: 16 },
      },
      dictOptions: {},
      superFieldList: [],
      strSelectedRowKeys: '', //多选后的id字符串值
    }
  },
  created() {
    this.partnerName = this.queryParam.partnerName
    this.contractType = this.queryParam.contractType
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
    downContractPdf: function () {
      return `${window._CONFIG['domianURL']}/${this.url.downContractPdf}`
    },
    /*createExamineBatch: function () {
        return `${window._CONFIG['domianURL']}/${this.url.createExamineBatch}`;
      },*/
  },
  methods: {
    initDictConfig() {},
    // 协议类型改变
    changeContarct(value) {
      this.queryParam.contractType = value
    },
    // 输入合作商改变
    changePartName(value) {
      this.queryParam.partnerName = value
    },
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'partnerName', text: '合作商', dictCode: '' })
      fieldList.push({ type: 'string', value: 'contractName', text: '合同', dictCode: '' })
      fieldList.push({ type: 'date', value: 'contractBegin', text: '合同开始日期' })
      fieldList.push({ type: 'date', value: 'contractEnd', text: '合同结束日期' })
      fieldList.push({ type: 'date', value: 'settleBegin', text: '结算开始日期' })
      fieldList.push({ type: 'date', value: 'settleEnd', text: '结算结束日期' })
      fieldList.push({ type: 'string', value: 'spRecord', text: '审批节点' })
      fieldList.push({ type: 'string', value: 'pkName', text: '源excel', dictCode: '' })
      fieldList.push({ type: 'int', value: 'spStatus', text: '合同状态', dictCode: 'sp_status' })
      fieldList.push({ type: 'string', value: 'settleTemplateName', text: '标准价格协议', dictCode: '' })
      fieldList.push({ type: 'string', value: 'spNo', text: '审批编号' })
      this.superFieldList = fieldList
    },
    onSelectChange(selectedRowKeys) {
      console.log('selectedRowKeys changed: ', selectedRowKeys)
      this.selectedRowKeys = selectedRowKeys
      this.strSelectedRowKeys = selectedRowKeys.join(',')
      console.log(this.strSelectedRowKeys)
    },
    onDateChange: function (value, dateString) {
      console.log(dateString[0], dateString[1])
      this.queryParam.createTime_begin = dateString[0]
      this.queryParam.createTime_end = dateString[1]
    },
    onDateOk(value) {
      console.log(value)
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>